<?php

// [ 生成评估报告 ]
/*
$file = ROOT_PATH . 'public' . DS . 'temp' . DS . 'tpl.jpg';
$imgArr = [$file,$file,$file,$file,$file];
$res  = Cpdf::run($imgArr);
p($res);
*/

namespace app\common\lib;
use app\common\lib\pdf\Fpdf;

class Cpdf
{
    public static function run($imgArr = [], $model = 'P')
    {
        if ( empty($imgArr) ) return ['result'=>false,'error'=>'imgArr empty'];

        $pdf = new Fpdf($model, 'cm', 'A4');

        foreach ($imgArr as $key => $val) {
            $pdf->AddPage();
            $pdf->Image($val, $x=0, $y=0, $w=0, $h=0, $type='', $link='');
        }

        $fileName = date('YmdHis') . rand(1000,9999) . '.pdf';
        $fileDir  = ROOT_PATH . 'public' . DS . 'cpdf' . DS . $fileName;
        $res = $pdf->Output('F',$fileDir);
        if ( empty($res) ) {
            $uri = '/public/cpdf/' . $fileName;
            return ['result'=>true,'uri'=>$uri];
        } else {
            return ['result'=>false,'error'=>$res];
        }
    }
}